// WizardImportLast.cpp : implementation file
//

#include "stdafx.h"
#include "calendar.h"
#include "WizardImportLast.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWizardImportLast property page

IMPLEMENT_DYNCREATE(CWizardImportLast, CPropertyPage)

CWizardImportLast::CWizardImportLast() : CPropertyPage(CWizardImportLast::IDD)
{
	//{{AFX_DATA_INIT(CWizardImportLast)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_imageList.Create(IDB_CHECK_EVENT, 16, 16, RGB(255,255,255));
}

CWizardImportLast::~CWizardImportLast()
{
}

void CWizardImportLast::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWizardImportLast)
	DDX_Control(pDX, IDC_TREE1, m_tree);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CWizardImportLast, CPropertyPage)
	//{{AFX_MSG_MAP(CWizardImportLast)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWizardImportLast message handlers

BOOL CWizardImportLast::OnWizardFinish() 
{
	HTREEITEM hti = m_tree.GetRootItem();

	while(hti) {
		CEvent *event = (CEvent *)m_tree.GetItemData(hti);
		event->bExport = m_tree.GetCheck(hti) == 1 ? true : false;

		hti = m_tree.GetNextSiblingItem(hti);
	}
	
	return CPropertyPage::OnWizardFinish();
}

BOOL CWizardImportLast::OnSetActive() 
{
	CPropertySheet *pSheet = (CPropertySheet *) GetParent();
	pSheet->SetWizardButtons(PSWIZB_FINISH | PSWIZB_BACK);

	m_tree.DeleteAllItems();

	POSITION pos = pDay->GetHeadPosition(); 
	CString name; HTREEITEM hti;

	while(pos) {
		CEvent &event = pDay->GetNext(pos);

		name.Format("%s", event.name); //, event.information);
		hti = m_tree.InsertItem(name, 2, 2, TVI_ROOT);
			
		event.bExport = true;
		m_tree.SetCheck(hti, TRUE);

		m_tree.SetItemData(hti, (DWORD) &event);
	}		
	
	m_tree.SortChildren(TVI_ROOT);
	
	return CPropertyPage::OnSetActive();
}

BOOL CWizardImportLast::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	m_tree.SetImageList(&m_imageList, TVSIL_NORMAL);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
